//
//  TempViewController.m
//  DZMCoverDemo
//
//  Created by 邓泽淼 on 16/10/8.
//  Copyright © 2016年 DZM. All rights reserved.
//

#import "TempViewController.h"
#import "DZMCoverController.h"
#import "HWSmoothViewController.h"
#import "HWSettingView.h"
#import "HWIndexView.h"
#import "HWNavgationView.h"
#import "HWPayBookView.h"
#import "HWMenuView.h"

@interface TempViewController ()<DZMCoverControllerDelegate,UIGestureRecognizerDelegate>
/**
 *  DZMCoverController
 */
@property (nonatomic,strong) DZMCoverController *coverVC;
@property (nonatomic,strong) HWSmoothViewController *smoothVC;

/**
 *  记录数字
 */
@property (nonatomic,assign) NSInteger number;
@property (nonatomic,strong) NSMutableArray *contentArr;

@property (nonatomic, strong)HWSettingView *setingView;
@property (nonatomic, strong)HWIndexView *indexView;
@property (nonatomic, strong)HWNavgationView *navgationView;
@property (nonatomic, strong)HWPayBookView *payBookView;
@property (nonatomic, strong)HWMenuView *menuView;
@property (nonatomic, assign)BOOL isOpenLight;
@property (nonatomic, assign)BOOL isHideMenu;
@property (nonatomic, assign)BOOL isHideIndex;

@property (nonatomic, strong)UIColor *bgColor;

@property (nonatomic, strong)HWBookReaderModel *model;

@property (nonatomic, assign)NSInteger nextPageId;
@property (nonatomic, assign)NSInteger prePageID;

@end

@implementation TempViewController

- (HWSmoothViewController *)smoothVC
{
    if (!_smoothVC)
    {
        _smoothVC = [[HWSmoothViewController alloc]init];
    }
    return _smoothVC;
}

- (NSMutableArray *)contentArr
{
    if (!_contentArr)
    {
        _contentArr = [[NSMutableArray alloc]init];
    }
    return _contentArr;
}

- (instancetype)init
{
    if (self = [super init])
    {
        self.number = 0;
        self.nextPageId = 0;
        self.prePageID = 0;
        self.bgColor = LCHexColor(0xf9f9f9);
    }
    
    return self;
}

- (HWMenuView *)menuView
{
    if (!_menuView)
    {
        _menuView = [[HWMenuView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT,SCREEN_WIDTH,TABBAR_HEIGHT+20*kUIScaleBasePlus)];
        _menuView.backgroundColor = [UIColor whiteColor];
        WeakSelf(self)
        _menuView.getMenuClickBlock = ^(NSString *str) {
            [weakSelf functionClick:str];
        };
        
        _menuView.turnOrCloseLightBlock = ^(BOOL light) {
            weakSelf.isOpenLight = light;
        };
    }
    return _menuView;
}

- (HWSettingView *)setingView
{
    if (!_setingView)
    {
        _setingView = [[HWSettingView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT,SCREEN_WIDTH,150*kUIScaleBasePlus)];
        _setingView.backgroundColor = [UIColor whiteColor];
        WeakSelf(self)
        _setingView.colorChangeBlock = ^(NSString *str) {
            [weakSelf changeBGColor:str];
        };
        
        _setingView.textFontChangeBlock = ^(NSInteger num) {
            NSArray *arr = [HWUtilties pagingWithContentString:[NSString stringWithFormat:@"%@\r\n\n %@",weakSelf.model.chapterTitle,weakSelf.model.chapterContent] contentSize:kContentSize textAttribute:@{NSFontAttributeName:[UIFont fontWithName:DCDefaultTextFontName size:num*kUIScaleBasePlus]}];
            [weakSelf.contentArr removeAllObjects];
            weakSelf.contentArr = [NSMutableArray arrayWithArray:arr];
            weakSelf.smoothVC.content = weakSelf.contentArr[weakSelf.number];
        };
        
        _setingView.cancelSettingViewBlock = ^{
            [weakSelf removeView];
        };
        
    }
    return _setingView;
}

- (HWIndexView *)indexView
{
    if (!_indexView)
    {
        _indexView = [[HWIndexView alloc]initWithFrame:CGRectMake(0,0,-SCREEN_WIDTH,SCREEN_HEIGHT)];
        
        WeakSelf(self)
        _indexView.upLoadIndexBlock = ^(NSString *page, NSString *size) {
            [weakSelf getIndexInfo:[weakSelf.model.bookId stringValue] page:page size:size];
        };
        
        _indexView.loadChapterBlock = ^(NSString *chapterId, NSString *chapterCoin) {
            [weakSelf getInfor:chapterId chapterCoin:chapterCoin];
            [UIView animateWithDuration:0.25 animations:^{
                weakSelf.indexView.frame = CGRectMake(0,0,-SCREEN_WIDTH,SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                weakSelf.indexView.hidden = YES;
                weakSelf.isHideIndex = YES;
                [weakSelf.indexView removeDate];
            }];
        };
        
        _indexView.hideIndexBlock = ^{
            [UIView animateWithDuration:0.25 animations:^{
                weakSelf.indexView.frame = CGRectMake(0,0,-SCREEN_WIDTH,SCREEN_HEIGHT);
                weakSelf.view.backgroundColor = weakSelf.bgColor;
                weakSelf.view.alpha = 1;
            } completion:^(BOOL finished) {
                weakSelf.isHideIndex = YES;
                [weakSelf.indexView removeDate];
                [weakSelf hideMenu];
                weakSelf.isHideMenu = YES;
                weakSelf.indexView.hidden = YES;
            }];
            
        };
    }
    return _indexView;
}

- (HWNavgationView *)navgationView
{
    if (!_navgationView)
    {
        _navgationView = [[HWNavgationView alloc]initWithFrame:CGRectMake(0,-(NAVIBAR_HEIGHT-10*kUIScaleBasePlus),SCREEN_WIDTH,NAVIBAR_HEIGHT-10*kUIScaleBasePlus)];
        _navgationView.hidden = YES;
        WeakSelf(self)
        _navgationView.getBackBlock = ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
        };
    }
    return _navgationView;
}

- (HWPayBookView *)payBookView
{
    if (!_payBookView)
    {
        _payBookView = [[HWPayBookView alloc]initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT-NAVIBAR_HEIGHT)];
        WeakSelf(self)
        _payBookView.paySuccessBlock = ^{
            [weakSelf getInfor:[weakSelf.model.chaperId stringValue] chapterCoin:[weakSelf.model.chapterCoin stringValue]];
            [weakSelf.payBookView removeFromSuperview];
            [UIView animateWithDuration:0.25 animations:^{
                weakSelf.indexView.frame = CGRectMake(0,0,-SCREEN_WIDTH,SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                weakSelf.isHideIndex = YES;
                [weakSelf.indexView removeDate];
            }];
        };
    }
    return _payBookView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 创建 内存已测试无内存泄漏
    DZMCoverController *coverVC = [[DZMCoverController alloc] init];
    coverVC.delegate = self;
    [self.view addSubview:coverVC.view];
    [self addChildViewController:coverVC];
    self.coverVC = coverVC;
    
    [self getInfor:self.chapterId chapterCoin:self.chapterCoin];
    
    [self creatUI];
}

- (void)creatUI
{
    self.isOpenLight = NO;
    self.isHideMenu = YES;
    self.isHideIndex = YES;
    
    [self.view addSubview:self.menuView];
    [self.view addSubview:self.setingView];
    [self.view addSubview:self.indexView];
    [self.view addSubview:self.navgationView];
    self.indexView.hidden = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showMenuClick:)];
    tap.numberOfTapsRequired =1;
    tap.numberOfTouchesRequired  =1;
    tap.delegate = self;
    [self.view addGestureRecognizer:tap];
    
    [self setNeedsStatusBarAppearanceUpdate];
}
#pragma mark - DZMCoverControllerDelegate

// 切换结果
- (void)coverController:(DZMCoverController *)coverController currentController:(UIViewController *)currentController finish:(BOOL)isFinish
{
    if (!isFinish) { // 切换失败
        
        HWSmoothViewController *vc = (HWSmoothViewController *)currentController;
        
    }
}

// 上一个控制器
- (UIViewController *)coverController:(DZMCoverController *)coverController getAboveControllerWithCurrentController:(UIViewController *)currentController
{
    
    
    if (!self.isHideMenu)
    {
        [self hideMenu];
        self.isHideMenu = YES;
    }
    
    
    if (self.prePageID == -1 && self.number == 0)
    {
        [HWUtilties showAlertWithTitle:nil content:@"已经是第一章了" buttonTitle:@"确定" ConfirmWithBlock:^{
            
        }];
        return nil;
    }
    else if(self.number == 0)
    {
        
        if (self.chapterFreeNum.integerValue <= [self.model.chapterOrder integerValue])
        {
            NSInteger payCoin = [self.model.giftCoin integerValue] + [self.model.bookCoin integerValue];
            if (payCoin < [self.model.preChapterCoin integerValue])
            {
                [self showPayView];
                return nil;
            }
            else if([self.model.autoCutPay integerValue] == 0)
            {
                [self showPayView];
            }
            else
            {
                if (self.payBookView)
                {
                    [self.payBookView removeFromSuperview];
                    [SVProgressHUD showWithStatus:@"加载中"];
                    return [self payBackChapter:[self.model.preChapterCoin stringValue] chapterId:[self.model.preChapterId stringValue]];;
                }
            }
        }
        else
        {
            [SVProgressHUD showWithStatus:@"加载中"];
            return [self payBackChapter:[self.model.preChapterCoin stringValue] chapterId:[self.model.preChapterId stringValue]];;
        }
    }
    else
    {
        self.number -= 1;
    }
    
    return [self viewControllerAtIndex:self.number];
}

// 下一个控制器
- (UIViewController *)coverController:(DZMCoverController *)coverController getBelowControllerWithCurrentController:(UIViewController *)currentController
{
    
    if (!self.isHideMenu)
    {
        [self hideMenu];
        self.isHideMenu = YES;
    }
    
    
    if (self.nextPageId == -1 && self.number == self.contentArr.count-1)
    {
        [HWUtilties showAlertWithTitle:nil content:@"已经是最后一章了" buttonTitle:@"确定" ConfirmWithBlock:^{
            
        }];
        return nil;
    }
    else if(self.number == self.contentArr.count-1)
    {
        
        if (self.chapterFreeNum.integerValue <= [self.model.chapterOrder integerValue])
        {
            NSInteger payCoin = [self.model.giftCoin integerValue] + [self.model.bookCoin integerValue];
            if (payCoin < [self.model.nextChapterCoin integerValue])
            {
                [self showPayView];
                return nil;
            }
            else if([self.model.autoCutPay integerValue] == 0)
            {
                [self showPayView];
            }
            else
            {
                if (self.payBookView)
                {
                    [self.payBookView removeFromSuperview];
                    [SVProgressHUD showWithStatus:@"加载中"];
                    return [self payBackChapter:[self.model.nextChapterCoin stringValue] chapterId:[self.model.nextChapterId stringValue]];
                }
            }
        }
        else
        {
            [SVProgressHUD showWithStatus:@"加载中"];
            return [self payBackChapter:[self.model.nextChapterCoin stringValue] chapterId:[self.model.nextChapterId stringValue]];
        }
    }
    else
    {
        self.number += 1;
    }
    
    
    return [self viewControllerAtIndex:self.number];
}

- (void)dealloc
{
    NSLog(@"ViewControllerCustom 释放了");
}

- (void)getInfor:(NSString *)chapterId chapterCoin:(NSString *)chapterCoin
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"chapterCoin" : chapterCoin,
                               @"chapterId" : chapterId
                               };
    
    WeakSelf(self)
    [MyInfoManager getBookContext:prarmers sucess:^(id  _Nonnull acceptData)
     {
         
         HWBookReaderModel *model = [[HWBookReaderModel alloc]initWithDic:acceptData];
         weakSelf.model = model;
         if (weakSelf.smoothVC)
         {
             NSArray *arr = [HWUtilties pagingWithContentString:[NSString stringWithFormat:@"%@\r\n\n %@",model.chapterTitle,model.chapterContent] contentSize:kContentSize textAttribute:@{NSFontAttributeName:[UIFont fontWithName:DCDefaultTextFontName size:20*kUIScaleBasePlus]}];
             [weakSelf.contentArr removeAllObjects];
             weakSelf.contentArr = [NSMutableArray arrayWithArray:arr];
             HWSmoothViewController *contentVC = [[HWSmoothViewController alloc] init];
             contentVC.content = arr[0];
             weakSelf.smoothVC = contentVC;
             weakSelf.nextPageId = [model.nextChapterId integerValue];
             weakSelf.prePageID = [model.preChapterId integerValue];
             [contentVC changeBgColor:LCHexColor(0xf9f9f9)];
             weakSelf.bgColor = LCHexColor(0xf9f9f9);
             [contentVC setIndex:0 totalPages:arr.count-1];
             [weakSelf.coverVC setController:contentVC];
             
             if (weakSelf.chapterFreeNum.integerValue <= [model.chapterOrder integerValue])
             {
                 NSInteger payCoin = [model.giftCoin integerValue] + [model.bookCoin integerValue];
                 if (payCoin < [model.chapterCoin integerValue] && self.number == arr.count-1)
                 {
                     [weakSelf showPayView];
                 }
                 else if([model.autoCutPay integerValue] == 0)
                 {
                     if (![chapterCoin isEqualToString:@"0"])
                     {
                         [weakSelf showPayView];
                     }
                 }
                 else
                 {
                     if (weakSelf.payBookView)
                     {
                         [weakSelf.payBookView removeFromSuperview];
                     }
                 }
             }
             
         }
        
     } fail:^(NSError * _Nullable error) {
         DISMISS_SVP(1.0f);
         [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
         DISMISS_SVP(1.0f);
     }];
}

- (void)payChapter:(NSString *)chapterCoin chapterId:(NSString *)chapterId
{
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"chapterCoin" : chapterCoin,
                               @"chapterId" : chapterId
                               };
    
    
    WeakSelf(self)
    [MyInfoManager getBookContextPay:prarmers sucess:^(id  _Nonnull acceptData)
     {
         [SVProgressHUD dismiss];
         
         HWBookReaderModel *model = [[HWBookReaderModel alloc]initWithDic:acceptData];
         weakSelf.model = model;
         
         if (weakSelf.smoothVC)
         {
             NSArray *arr = [HWUtilties pagingWithContentString:[NSString stringWithFormat:@"%@\r\n\n %@",model.chapterTitle,model.chapterContent] contentSize:kContentSize textAttribute:@{NSFontAttributeName:[UIFont fontWithName:DCDefaultTextFontName size:20*kUIScaleBasePlus]}];
             [weakSelf.contentArr removeAllObjects];
             weakSelf.contentArr = [NSMutableArray arrayWithArray:arr];
             HWSmoothViewController *contentVC = [[HWSmoothViewController alloc] init];
             weakSelf.smoothVC = contentVC;
             [contentVC changeBgColor:self.bgColor];
             weakSelf.nextPageId = [model.nextChapterId integerValue];
             weakSelf.prePageID = [model.preChapterId integerValue];
             contentVC.content = arr[0];
             [contentVC setIndex:0 totalPages:arr.count-1];
             [weakSelf.coverVC setController:contentVC];
             weakSelf.number = 0;
         }
         
     } fail:^(NSError * _Nullable error) {
         DISMISS_SVP(1.0f);
         [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
         DISMISS_SVP(1.0f);
     }];
}

- (HWSmoothViewController *)payBackChapter:(NSString *)chapterCoin chapterId:(NSString *)chapterId
{
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"chapterCoin" : chapterCoin,
                               @"chapterId" : chapterId
                               };
    
    HWSmoothViewController *contentVC = [[HWSmoothViewController alloc] init];
    
    WeakSelf(self)
    [MyInfoManager getBookContextPay:prarmers sucess:^(id  _Nonnull acceptData)
     {
         [SVProgressHUD dismiss];
         
         HWBookReaderModel *model = [[HWBookReaderModel alloc]initWithDic:acceptData];
         weakSelf.model = model;
         
         if (weakSelf.smoothVC)
         {
             NSArray *arr = [HWUtilties pagingWithContentString:[NSString stringWithFormat:@"%@\r\n\n %@",model.chapterTitle,model.chapterContent] contentSize:kContentSize textAttribute:@{NSFontAttributeName:[UIFont fontWithName:DCDefaultTextFontName size:20*kUIScaleBasePlus]}];
             [contentVC changeBgColor:self.bgColor];
             weakSelf.smoothVC = contentVC;
             weakSelf.nextPageId = [model.nextChapterId integerValue];
             weakSelf.prePageID = [model.preChapterId integerValue];
             
             if (weakSelf.number == weakSelf.contentArr.count - 1)
             {
                 contentVC.content = arr[0];
                 [contentVC setIndex:0 totalPages:arr.count-1];
                 weakSelf.number = 0;
             }
             else if(weakSelf.number == 0)
             {
                 contentVC.content = [arr lastObject];
                 [contentVC setIndex:arr.count totalPages:arr.count-1];
                 weakSelf.number = arr.count-1;
             }
             [weakSelf.contentArr removeAllObjects];
             weakSelf.contentArr = [NSMutableArray arrayWithArray:arr];
         }
         
     } fail:^(NSError * _Nullable error) {
         DISMISS_SVP(1.0f);
         [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
         DISMISS_SVP(1.0f);
     }];
    
    return contentVC;
}


- (HWSmoothViewController *)viewControllerAtIndex:(NSUInteger)index
{
  
    // 创建一个新的控制器类，并且分配给相应的数据
    HWSmoothViewController *contentVC = [[HWSmoothViewController alloc] init];
    contentVC.content = [self.contentArr objectAtIndex:index];
    [contentVC setIndex:index totalPages:self.contentArr.count-1];
    [contentVC changeBgColor:self.bgColor];
    self.smoothVC = contentVC;
    [self setNeedsStatusBarAppearanceUpdate];

    
    return contentVC;
}


- (void)showPayView
{
    [self.view addSubview:self.payBookView];
    [self.payBookView getInfo:self.model];
}

- (void)functionClick:(NSString *)str
{
    WeakSelf(self)
    switch (str.integerValue)
    {
        case 0:
        {
            if (self.chapterFreeNum.integerValue <= [self.model.chapterOrder integerValue])
            {
                NSInteger payCoin = [self.model.giftCoin integerValue] + [self.model.bookCoin integerValue];
                if (payCoin < [self.model.preChapterCoin integerValue])
                {
                    [self showPayView];
                }
                else if([self.model.autoCutPay integerValue] == 0)
                {
                    [self showPayView];
                }
                else
                {
                    if (self.payBookView)
                    {
                        [self.payBookView removeFromSuperview];
                        
                    }
                    [SVProgressHUD showWithStatus:@"加载中"];
                    [self payChapter:[self.model.preChapterCoin stringValue] chapterId:[self.model.preChapterId stringValue]];
                }
            }
            else
            {
                [SVProgressHUD showWithStatus:@"加载中"];
                [self payChapter:[self.model.preChapterCoin stringValue] chapterId:[self.model.preChapterId stringValue]];
            }
        }
            break;
        case 1:
        {
            self.indexView.hidden = NO;
            [self hideMenu];
            self.isHideMenu = YES;
            [self getIndexInfo:[self.model.bookId stringValue] page:@"1" size:@"30"];
        }
            break;
        case 2:
        {
            [UIView animateWithDuration:0.5 animations:^{
                weakSelf.setingView.frame = CGRectMake(0,SCREEN_HEIGHT-150*kUIScaleBasePlus,SCREEN_WIDTH,150*kUIScaleBasePlus);
            } completion:^(BOOL finished) {
                
            }];
        }
            break;
        case 3:
        {
            if (self.isOpenLight)
            {
                [self.smoothVC changeBgColor:LCHexColor(0xf9f9f9)];
                self.bgColor = LCHexColor(0xf9f9f9);
            }
            else
            {
                [self.smoothVC changeBgColor:LCHexColor(0x1d1d1f)];
                self.bgColor = LCHexColor(0x1d1d1f);
            }
        }
            break;
        case 4:
        {
            
            if (self.chapterFreeNum.integerValue <= [self.model.chapterOrder integerValue])
            {
                NSInteger payCoin = [self.model.giftCoin integerValue] + [self.model.bookCoin integerValue];
                if (payCoin < [self.model.nextChapterCoin integerValue])
                {
                    [self showPayView];
                }
                else if([self.model.autoCutPay integerValue] == 0)
                {
                    [self showPayView];
                }
                else
                {
                    if (self.payBookView)
                    {
                        [self.payBookView removeFromSuperview];
                    }
                    [SVProgressHUD showWithStatus:@"加载中"];
                    [self payChapter:[self.model.nextChapterCoin stringValue] chapterId:[self.model.nextChapterId stringValue]];
                }
            }
            else
            {
                [SVProgressHUD showWithStatus:@"加载中"];
                [self payChapter:[self.model.nextChapterCoin stringValue] chapterId:[self.model.nextChapterId stringValue]];
            }

        }
            break;
        default:
            break;
    }
    
    
}

- (void)changeBGColor:(NSString *)str
{
    
    switch (str.integerValue)
    {
        case 0:
        {
            [self.view setBackgroundColor:LCHexColor(0xf9f9f9)];
            self.bgColor = LCHexColor(0xf9f9f9);
        }
            break;
        case 1:
        {
            [self.view setBackgroundColor:LCHexColor(0xf3e7d0)];
            self.bgColor = LCHexColor(0xf3e7d0);
        }
            break;
        case 2:
        {
            [self.view setBackgroundColor:LCHexColor(0xc0dea4)];
            self.bgColor = LCHexColor(0xc0dea4);
        }
            break;
        case 3:
        {
            [self.view setBackgroundColor:LCHexColor(0x1d1d1f)];
            self.bgColor = LCHexColor(0x1d1d1f);
        }
            break;
        default:
            break;
    }
    
    [self.smoothVC changeBgColor:self.bgColor];
    
}

- (void)removeView
{
    WeakSelf(self)
    [UIView animateWithDuration:0.5 animations:^{
        weakSelf.setingView.frame = CGRectMake(0,SCREEN_HEIGHT,SCREEN_WIDTH,150*kUIScaleBasePlus);
    } completion:^(BOOL finished) {
        
    }];
}

- (void)showMenu
{
    self.navgationView.hidden = NO;
    WeakSelf(self)
    [UIView animateWithDuration:0.5 animations:^{
        weakSelf.menuView.frame = CGRectMake(0,SCREEN_HEIGHT-TABBAR_HEIGHT-20*kUIScaleBasePlus,SCREEN_WIDTH,TABBAR_HEIGHT+20*kUIScaleBasePlus);
        weakSelf.navgationView.frame = CGRectMake(0,0,SCREEN_WIDTH,NAVIBAR_HEIGHT-10*kUIScaleBasePlus);
    } completion:^(BOOL finished) {
        
    }];
}

- (void)hideMenu
{
    WeakSelf(self)
    [UIView animateWithDuration:0.5 animations:^{
        weakSelf.menuView.frame = CGRectMake(0,SCREEN_HEIGHT,SCREEN_WIDTH,TABBAR_HEIGHT+20*kUIScaleBasePlus);
        weakSelf.navgationView.frame = CGRectMake(0,-(NAVIBAR_HEIGHT-10*kUIScaleBasePlus),SCREEN_WIDTH,NAVIBAR_HEIGHT-10*kUIScaleBasePlus);
        weakSelf.setingView.frame = CGRectMake(0,SCREEN_HEIGHT,SCREEN_WIDTH,150*kUIScaleBasePlus);
    } completion:^(BOOL finished) {
        self.navgationView.hidden = YES;
    }];
}

- (void)showMenuClick:(UIGestureRecognizer *)sender
{
    if (self.isHideMenu)
    {
        [self showMenu];
        self.isHideMenu = NO;
    }
    else
    {
        [self hideMenu];
        self.isHideMenu = YES;
    }
    
    [self setNeedsStatusBarAppearanceUpdate];
}

#pragma mark - 加载目录
- (void)getIndexInfo:(NSString *)bookId page:(NSString *)page size:(NSString *)size
{
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"bookId" : bookId,
                               @"pageNum" : page,
                               @"pageSize" : size
                               };
    
    WeakSelf(self)
    [MyInfoManager getBookIndexInfo:prarmers sucess:^(id  _Nonnull acceptData)
     {
         NSNumber *nub = IFNULL(acceptData[@"hasNextPage"], [NSNumber new]);
         
         [weakSelf.indexView getDate:acceptData[@"list"] hasNetPage:nub];
         
         if (weakSelf.isHideIndex)
         {
             [UIView animateWithDuration:0.25 animations:^{
                 weakSelf.indexView.frame = CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
                 weakSelf.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.75];
             } completion:^(BOOL finished) {
                 weakSelf.isHideIndex = NO;
             }];
         }
         
     } fail:^(NSError * _Nullable error) {
         DISMISS_SVP(1.0f);
         [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
         DISMISS_SVP(1.0f);
     }];
}


- (BOOL)prefersStatusBarHidden
{
    if(!self.isHideMenu)
    {
        return NO;
    }else
    {
        return YES;
    }
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    // 点击的view的类名
    NSLog(@"%@", NSStringFromClass([touch.view class]));
    // 点击了tableViewCell，view的类名为UITableViewCellContentView，则不接收Touch点击事件
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"])
    {
        return NO;
    }
    return  YES;
}

@end
